# encoding: utf-8
""" 
@version: v1.0 
@author: autumner 
@license: Apache Licence  
@contact: 18322313385@163.com 
@site:  
@software: PyCharm 
@file: snowView.py 
@time: 2018/8/10 14:51
"""
'''
利用turtle画一个雪花场景
'''

import turtle as t
from random import randint, random


def drawSnow():
    t.hideturtle()
    t.pensize(2)
    for i in range(100):
        r, g, b = random(), random(), random()
        t.pencolor(r, g, b)
        t.up()
        t.setx(randint(-350, 350))
        t.sety(randint(1, 270))
        t.pd()
        dens = randint(8, 12)
        snowsize = randint(10, 14)
        for j in range(dens):
            t.fd(snowsize)
            t.backward(snowsize)
            t.rt(360/dens)


def drawGround():
    t.hideturtle()
    for i in range(400):
        t.pensize(randint(5, 10))
        x = randint(-400, 350)
        y = randint(-280, -1)
        r, g, b =  -y/280, -y/280, -y/280
        t.pencolor(r, g, b)
        t.up()
        t.goto(x, y)
        t.pd()
        t.fd(randint(40, 100))


t.setup(800, 600, 200, 200)
t.tracer(False)  #停止屏幕刷新, t.tarcer(1, 0) 每1次操作将屏幕刷新，延时为0
t.bgcolor('black')
drawSnow()
drawGround()
t.done()